package com.ztq.test.login.action;

import com.ztq.test.login.entity.T_userInfo;
import com.ztq.test.login.service.LoginService;
import com.ztq.test.system.util.CommonUtils;

/**
 * @author: ztq
 * @date: 2016-1-8 下午03:21:23
 * @description: 处于用户登录注册相关逻辑
 * @version:1.0
 */
public class LoginAction {
	private T_userInfo userInfo;
	private LoginService loginService;
	
	public LoginService getLoginService() {
		return loginService;
	}

	public void setLoginService(LoginService loginService) {
		this.loginService = loginService;
	}

	public T_userInfo getUserInfo() {
		return userInfo;
	}

	public void setUserInfo(T_userInfo userInfo) {
		this.userInfo = userInfo;
	}

	// 处理用户登录的响应
	public String login(){
		String result = null;
		if(!loginService.judgeUsernameExist(userInfo)){
			result = "login result: username not exist";
		} else{
			if(!loginService.judgePasswordExist(userInfo)){
				result = "login result: password error";
			}else{
				result = "login result: success";
				result += ";" + loginService.getUserId(userInfo);
			}
		}
		CommonUtils.responseWrite(result);
		return null;
	}
	
	//处理用户注册的响应
	public String register(){
		String result = null;
		if(loginService.judgeUsernameExist(userInfo)){
			result = "register result: username exist";
		}else{
			if(loginService.judgeEmailExist(userInfo)){
				result = "register result: email exist";
			} else{
				if(loginService.register(userInfo)){
					result = "register result: success";
				}else{
					result = "register result: fail";
				}
			}
		}
		CommonUtils.responseWrite(result);
		return null;
	}
}